<!DOCTYPE html>
<html>
<head>
    <title>Test Export</title>
</head>
<body>
    <h1>测试导出功能</h1>
    <button onclick="testExport()">测试导出</button>
    <div id="result"></div>

    <script>
        async function testExport() {
            try {
                const content = {
                    title: '前端测试文章',
                    content: `
                        <h1>前端测试文章</h1>
                        <p>这是通过前端API测试的导出功能。</p>
                        <h2>测试内容</h2>
                        <p>包含各种HTML格式的测试。</p>
                        <pre><code>console.log('测试代码');</code></pre>
                    `
                };
                
                const response = await fetch('/api/export-to-word', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ 
                        content: content, 
                        filename: '前端测试导出.docx' 
                    })
                });
                
                const result = await response.json();
                
                if (result.success) {
                    document.getElementById('result').innerHTML = 
                        `<p style="color: green;">✅ 导出成功！<br>文件路径: ${result.filePath}</p>`;
                } else {
                    document.getElementById('result').innerHTML = 
                        `<p style="color: red;">❌ 导出失败: ${result.error}</p>`;
                }
                
            } catch (error) {
                document.getElementById('result').innerHTML = 
                    `<p style="color: red;">❌ 测试失败: ${error.message}</p>`;
            }
        }
    </script>
</body>
</html>